from tkinter import messagebox

import pymysql
import tkinter as tk


# 商品表的添加
def add_sp():
    # 连接数据库
    connect = pymysql.connect(host="localhost", user="root", password="hsb010811", database="618")
    # 创建光标
    cursor = connect.cursor()
    # 编写SQL语句
    sql = "insert into 商品表(商品编号,商品名称,商品单价,供应商编号,商品简介,备注) values('%s','%s','%s','%s','%s','%s')", (v1.get(), v2.get(), v3.get(), v4.get(), v5.get(), v6.get())
    # 执行SQL语句，并且输出完成提示信息，否则回滚
    try:
        cursor.execute(sql)
        connect.commit()
        tk.messagebox.showinfo("提示", "数据添加成功")
    except:
        connect.rollback()
    # 关闭数据库连接，防止泄露
    connect.close()


# 员工表的添加
def add_yg():
    # 连接数据库
    connect = pymysql.connect(host="localhost", user="root", password="hsb010811", database="618")
    # 创建光标
    cursor = connect.cursor()
    # 编写SQL语句
    sql = "insert into 员工表(员工编号,员工姓名,员工密码,员工级别,员工电话,员工工资,备注) values('%s','%s','%s','%s','%s','%s','%s')" % (v1.get(), v2.get(), v3.get(), v4.get(), v5.get(), v6.get(), v7.get())

    # 执行SQL语句，并且输出完成提示信息，否则回滚
    try:
        cursor.execute(sql)
        connect.commit()
        tk.messagebox.showinfo("提示", "数据添加成功")
    except:
        connect.rollback()
    # 关闭数据库连接，防止泄露
    connect.close()


# 供应商表的添加
def add_gys():
    # 连接数据库
    connect = pymysql.connect(host="localhost", user="root", password="hsb010811", database="618")
    # 创建光标
    cursor = connect.cursor()
    # 编写SQL语句
    sql = "insert into 供应商表(供应商编号,供应商名称,供应商简称,地址,公司电话,邮件,联系人,联系人电话,备注) values('%s','%s','%s','%s','%s','%s','%s,'%s','%s')" % (v1.get(), v2.get(), v3.get(), v4.get(), v5.get(), v6.get(), v7.get(), v8.get(), v9.get())
    # 执行SQL语句，并且输出完成提示信息，否则回滚
    try:
        cursor.execute(sql)
        connect.commit()
        tk.messagebox.showinfo("提示", "数据添加成功")
    except:
        connect.rollback()
    # 关闭数据库连接，防止泄露
    connect.close()


# 采购主表的添加
def add_cg():
    # 连接数据库
    connect = pymysql.connect(host="localhost", user="root", password="hsb010811", database="618")
    # 创建光标
    cursor = connect.cursor()
    # 编写SQL语句
    sql = "insert into 采购主表(采购清单号,员工编号,采购数量,采购总价,采购时间,备注) values('%s','%s','%s','%s','%s','%s')" % (v1.get(), v2.get(), v3.get(), v4.get(), v5.get(), v6.get())
    # 执行SQL语句，并且输出完成提示信息，否则回滚
    try:
        cursor.execute(sql)
        connect.commit()
        tk.messagebox.showinfo("提示", "数据添加成功")
    except:
        connect.rollback()
    # 关闭数据库连接，防止泄露
    connect.close()


# 采购明细表的添加
def add_mx():
    # 连接数据库
    connect = pymysql.connect(host="localhost", user="root", password="hsb010811", database="618")
    # 创建光标
    cursor = connect.cursor()
    # 编写SQL语句
    sql = "insert into 采购主表(采购明细号,采购清单号,商品编号,采购数量,商品单价,商品总价,备注) values('%s','%s','%s','%s','%s','%s','%s')" % (v1.get(), v2.get(), v3.get(), v4.get(), v5.get(), v6.get(), v7.get())
    # 执行SQL语句，并且输出完成提示信息，否则回滚
    try:
        cursor.execute(sql)
        connect.commit()
        tk.messagebox.showinfo("提示", "数据添加成功")
    except:
        connect.rollback()
    # 关闭数据库连接，防止泄露
    connect.close()


# 商品表的删除
def delete_sp():
    # 连接数据库
    connect = pymysql.connect(host="localhost", user="root", password="hsb010811", database="618")
    # 创建光标
    cursor = connect.cursor()
    # 编写SQL语句
    sql = "delete from 商品表 where 商品编号='%s'" % (v1.get())
    # 执行SQL语句，并且输出完成提示信息，否则回滚
    try:
        cursor.execute(sql)
        connect.commit()
        tk.messagebox.showinfo("提示", "数据删除成功")
    except:
        connect.rollback()
    # 关闭数据库连接，防止泄露
    connect.close()


# 员工表的删除
def delete_yg():
    # 连接数据库
    connect = pymysql.connect(host="localhost", user="root", password="hsb010811", database="618")
    # 创建光标
    cursor = connect.cursor()
    # 编写SQL语句
    sql = "delete from 员工表 where 员工编号='%s'" % (v1.get())
    # 执行SQL语句，并且输出完成提示信息，否则回滚
    try:
        cursor.execute(sql)
        connect.commit()
        tk.messagebox.showinfo("提示", "数据删除成功")
    except:
        connect.rollback()
    # 关闭数据库连接，防止泄露
    connect.close()


# 供应商表的删除
def delete_gys():
    # 连接数据库
    connect = pymysql.connect(host="localhost", user="root", password="hsb010811", database="618")
    # 创建光标
    cursor = connect.cursor()
    # 编写SQL语句
    sql = "delete from 供应商表 where 供应商编号='%s'" % (v1.get())
    # 执行SQL语句，并且输出完成提示信息，否则回滚
    try:
        cursor.execute(sql)
        connect.commit()
        tk.messagebox.showinfo("提示", "数据删除成功")
    except:
        connect.rollback()
    # 关闭数据库连接，防止泄露
    connect.close()


# 采购主表的删除
def delete_cg():
    # 连接数据库
    connect = pymysql.connect(host="localhost", user="root", password="hsb010811", database="618")
    # 创建光标
    cursor = connect.cursor()
    # 编写SQL语句
    sql = "delete from 采购主表 where 采购清单号='%s'" % (v1.get())
    # 执行SQL语句，并且输出完成提示信息，否则回滚
    try:
        cursor.execute(sql)
        connect.commit()
        tk.messagebox.showinfo("提示", "数据删除成功")
    except:
        connect.rollback()
    # 关闭数据库连接，防止泄露
    connect.close()


# 采购明细表的删除
def delete_mx():
    # 连接数据库
    connect = pymysql.connect(host="localhost", user="root", password="hsb010811", database="618")
    # 创建光标
    cursor = connect.cursor()
    # 编写SQL语句
    sql = "delete from 采购明细表 where 采购明细号='%s'" % (v1.get())
    # 执行SQL语句，并且输出完成提示信息，否则回滚
    try:
        cursor.execute(sql)
        connect.commit()
        tk.messagebox.showinfo("提示", "数据删除成功")
    except:
        connect.rollback()
    # 关闭数据库连接，防止泄露
    connect.close()


# 商品表的更新
def update_sp():
    connect = pymysql.connect(host="localhost", user="root", password="hsb010811", database="618")
    cursor = connect.cursor()
    sql = "update 商品表 set 商品编号 ='%s', 商品名称='%s',商品单价='%s',供应商编号='%s',商品简介='%s',备注='%s' where 商品编号='%s"
    try:
        cursor.execute(sql)
        connect.commit()
        tk.messagebox.showinfo("提示", "数据更新成功！")
    except:
        connect.rollback()
    connect.close()


# 商品表的查询
def select_sp():
    # 建立连接
    connect = pymysql.connect(host="localhost", user="root", password="hsb010811", database="618")
    cursor = connect.cursor()
    # 定义变量记录输入信息
    v1 = tk.StringVar()
    sql = "select * from 商品表 where 商品编号=%s" % (v1.get())
    try:
        cursor.execute(sql)
        results = cursor.fetchall()
        tk.messagebox.showinfo(title='商品表', message=results)
    except:
        return


# 增-商品表界面
def add_sp_page():
    # window.destroy()
    # 构建全集变量，方便上面的函数调用
    global window_function
    global v1,v2,v3,v4,v5,v6
    # 生成窗口
    window_function = tk.Tk()
    # 窗口标题
    window_function.title("超市管理系统")
    # 窗口大小
    width = 400
    height = 500
    screenwidth = window_function.winfo_screenwidth()
    screenheight = window_function.winfo_screenheight()
    size_geo = '%dx%d+%d+%d' % (width, height, (screenwidth - width) / 2, (screenheight - height) / 2)
    window_function.geometry(size_geo)
    # 生成标签
    tk.Label(window_function, text="添加新商品", font=("黑体", 20)).grid(row=0, column=1, pady=10)
    tk.Label(window_function, text="请输入商品编号：").grid(row=1, column=0, padx=20, pady=20)
    tk.Label(window_function, text="请输入商品名称：").grid(row=2, column=0, padx=20, pady=20)
    tk.Label(window_function, text="请输入商品单价：").grid(row=3, column=0, padx=20, pady=20)
    tk.Label(window_function, text="请输入供应商编号：").grid(row=4, column=0, padx=20, pady=20)
    tk.Label(window_function, text="请输入商品简介：").grid(row=5, column=0, padx=20, pady=20)
    tk.Label(window_function, text="请输入备注内容：").grid(row=6, column=0, padx=20, pady=20)
    # 定义变量记录输入信息
    v1 = tk.StringVar()
    v2 = tk.StringVar()
    v3 = tk.StringVar()
    v4 = tk.StringVar()
    v5 = tk.StringVar()
    v6 = tk.StringVar()
    # 生成输入框
    entry1 = tk.Entry(window_function, show=None, textvariable=v1).grid(row=1, column=1)
    entry2 = tk.Entry(window_function, show=None, textvariable=v2).grid(row=2, column=1)
    entry3 = tk.Entry(window_function, show=None, textvariable=v3).grid(row=3, column=1)
    entry4 = tk.Entry(window_function, show=None, textvariable=v4).grid(row=4, column=1)
    entry5 = tk.Entry(window_function, show=None, textvariable=v5).grid(row=5, column=1)
    entry6 = tk.Entry(window_function, show=None, textvariable=v6).grid(row=6, column=1)
    # 生成按钮
    button = tk.Button(window_function, text="添加", command=add_sp).place(relx=0.3, rely=0.9)
    button2 = tk.Button(window_function, text="返回", command=to_sp_page).place(relx=0.5, rely=0.9)
    # 显示窗口
    window_function.mainloop()


# 增-员工表界面
def add_yg_page():
    # 构建全集变量，方便上面的函数调用
    global window_function
    global v1,v2,v3,v4,v5,v6,v7
    # 生成窗口
    window_function = tk.Tk()
    # 窗口标题
    window_function.title("超市管理系统")
    # 窗口大小
    width = 400
    height = 500
    screenwidth = window_function.winfo_screenwidth()
    screenheight = window_function.winfo_screenheight()
    size_geo = '%dx%d+%d+%d' % (width, height, (screenwidth - width) / 2, (screenheight - height) / 2)
    window_function.geometry(size_geo)
    # 生成标签
    tk.Label(window_function, text="添加新员工", font=("黑体", 20)).grid(row=0, column=1, pady=10)
    tk.Label(window_function, text="请输入员工编号：").grid(row=1, column=0, padx=20, pady=10)
    tk.Label(window_function, text="请输入员工姓名：").grid(row=2, column=0, padx=20, pady=10)
    tk.Label(window_function, text="请输入员工密码：").grid(row=3, column=0, padx=20, pady=10)
    tk.Label(window_function, text="请输入员工级别：").grid(row=4, column=0, padx=20, pady=10)
    tk.Label(window_function, text="请输入员工电话：").grid(row=5, column=0, padx=20, pady=10)
    tk.Label(window_function, text="请输入员工工资：").grid(row=6, column=0, padx=20, pady=10)
    tk.Label(window_function, text="请输入备注内容：").grid(row=7, column=0, padx=20, pady=10)
    # 定义变量记录输入信息
    v1 = tk.StringVar()
    v2 = tk.StringVar()
    v3 = tk.StringVar()
    v4 = tk.StringVar()
    v5 = tk.StringVar()
    v6 = tk.StringVar()
    v7 = tk.StringVar()
    # 生成输入框
    entry1 = tk.Entry(window_function, show=None, textvariable=v1).grid(row=1, column=1)
    entry2 = tk.Entry(window_function, show=None, textvariable=v2).grid(row=2, column=1)
    entry3 = tk.Entry(window_function, show=None, textvariable=v3).grid(row=3, column=1)
    entry4 = tk.Entry(window_function, show=None, textvariable=v4).grid(row=4, column=1)
    entry5 = tk.Entry(window_function, show=None, textvariable=v5).grid(row=5, column=1)
    entry6 = tk.Entry(window_function, show=None, textvariable=v6).grid(row=6, column=1)
    entry7 = tk.Entry(window_function, show=None, textvariable=v7).grid(row=7, column=1)
    # 生成按钮
    button = tk.Button(window_function, text="添加", command=add_yg).place(relx=0.3, rely=0.9)
    button2 = tk.Button(window_function, text="返回", command=to_yg_page).place(relx=0.5, rely=0.9)
    # 显示窗口
    window_function.mainloop()


# 增-供应商表界面
def add_gys_page():
    # 构建全集变量，方便上面的函数调用
    global window_function
    global v1,v2,v3,v4,v5,v6,v7,v8,v9
    # 生成窗口
    window_function = tk.Tk()
    # 窗口标题
    window_function.title("超市管理系统")
    # 窗口大小
    width = 400
    height = 500
    screenwidth = window_function.winfo_screenwidth()
    screenheight = window_function.winfo_screenheight()
    size_geo = '%dx%d+%d+%d' % (width, height, (screenwidth - width) / 2, (screenheight - height) / 2)
    window_function.geometry(size_geo)
    # 生成标签
    tk.Label(window_function, text="添加新供应商", font=("黑体", 20)).grid(row=0, column=1, pady=10)
    tk.Label(window_function, text="请输入供应商编号：").grid(row=1, column=0, padx=20, pady=10)
    tk.Label(window_function, text="请输入供应商名称：").grid(row=2, column=0, padx=20, pady=10)
    tk.Label(window_function, text="请输入供应商简称：").grid(row=3, column=0, padx=20, pady=10)
    tk.Label(window_function, text="请输入地址：").grid(row=4, column=0, padx=20, pady=10)
    tk.Label(window_function, text="请输入公司电话：").grid(row=5, column=0, padx=20, pady=10)
    tk.Label(window_function, text="请输入邮件：").grid(row=6, column=0, padx=20, pady=10)
    tk.Label(window_function, text="请输入联系人：").grid(row=7, column=0, padx=20, pady=10)
    tk.Label(window_function, text="请输入联系人电话：").grid(row=8, column=0, padx=20, pady=10)
    tk.Label(window_function, text="请输入备注内容：").grid(row=9, column=0, padx=20, pady=10)
    # 定义变量记录输入信息
    v1 = tk.StringVar()
    v2 = tk.StringVar()
    v3 = tk.StringVar()
    v4 = tk.StringVar()
    v5 = tk.StringVar()
    v6 = tk.StringVar()
    v7 = tk.StringVar()
    v8 = tk.StringVar()
    v9 = tk.StringVar()
    # 生成输入框
    entry1 = tk.Entry(window_function, show=None, textvariable=v1).grid(row=1, column=1)
    entry2 = tk.Entry(window_function, show=None, textvariable=v2).grid(row=2, column=1)
    entry3 = tk.Entry(window_function, show=None, textvariable=v3).grid(row=3, column=1)
    entry4 = tk.Entry(window_function, show=None, textvariable=v4).grid(row=4, column=1)
    entry5 = tk.Entry(window_function, show=None, textvariable=v5).grid(row=5, column=1)
    entry6 = tk.Entry(window_function, show=None, textvariable=v6).grid(row=6, column=1)
    entry7 = tk.Entry(window_function, show=None, textvariable=v7).grid(row=7, column=1)
    entry8 = tk.Entry(window_function, show=None, textvariable=v8).grid(row=8, column=1)
    entry9 = tk.Entry(window_function, show=None, textvariable=v9).grid(row=9, column=1)
    # 生成按钮
    button = tk.Button(window_function, text="添加", command=add_gys).place(relx=0.3, rely=0.9)
    button2 = tk.Button(window_function, text="返回", command=to_gys_page).place(relx=0.5, rely=0.9)
    # 显示窗口
    window_function.mainloop()


# 删除商品界面
def delete_sp_page():
    # window.destroy()
    global window_function
    global v1
    window_function = tk.Tk()
    window_function.title("超市管理系统")
    width = 400
    height = 500
    screenwidth = window_function.winfo_screenwidth()
    screenheight = window_function.winfo_screenheight()
    size_geo = '%dx%d+%d+%d' % (width, height, (screenwidth - width) / 2, (screenheight - height) / 2)
    window_function.geometry(size_geo)

    tk.Label(window_function, text="删除商品", font=("黑体", 20)).grid(row=0, column=1, pady=20)
    tk.Label(window_function, text="请输入商品编号：").grid(row=1, column=0, padx=20)
    # 定义变量记录输入信息
    v1 = tk.StringVar()
    # 生成输入框
    entry1 = tk.Entry(window_function, show=None, textvariable=v1).grid(row=1, column=1, pady=40)
    # 生成按钮
    button = tk.Button(window_function, text="删除", command=delete_sp, anchor='s').place(relx=0.2, rely=0.5)
    button2 = tk.Button(window_function, text="返回", command=to_sp_page).place(relx=0.4, rely=0.5)
    # 显示窗口
    window_function.mainloop()


# 删除供应商界面
def delete_gys_page():
    # window.destroy()
    global window_function
    global v1
    window_function = tk.Tk()
    window_function.title("超市管理系统")
    width = 400
    height = 500
    screenwidth = window_function.winfo_screenwidth()
    screenheight = window_function.winfo_screenheight()
    size_geo = '%dx%d+%d+%d' % (width, height, (screenwidth - width) / 2, (screenheight - height) / 2)
    window_function.geometry(size_geo)

    tk.Label(window_function, text="删除供应商", font=("黑体", 20)).grid(row=0, column=1, pady=20)
    tk.Label(window_function, text="请输入供应商编号：").grid(row=1, column=0, padx=20)
    # 定义变量记录输入信息
    v1 = tk.StringVar()
    # 生成输入框
    entry1 = tk.Entry(window_function, show=None, textvariable=v1).grid(row=1, column=1, pady=40)
    # 生成按钮
    button = tk.Button(window_function, text="删除", command=delete_gys, anchor='s').place(relx=0.2, rely=0.5)
    button2 = tk.Button(window_function, text="返回", command=to_gys_page).place(relx=0.4, rely=0.5)
    # 显示窗口
    window_function.mainloop()


# 删除员工界面
def delete_yg_page():
    # window.destroy()
    global window_function
    global v1
    window_function = tk.Tk()
    window_function.title("超市管理系统")
    width = 400
    height = 500
    screenwidth = window_function.winfo_screenwidth()
    screenheight = window_function.winfo_screenheight()
    size_geo = '%dx%d+%d+%d' % (width, height, (screenwidth - width) / 2, (screenheight - height) / 2)
    window_function.geometry(size_geo)

    tk.Label(window_function, text="删除员工", font=("黑体", 20)).grid(row=0, column=1, pady=20)
    tk.Label(window_function, text="请输入员工编号：").grid(row=1, column=0, padx=20)
    # 定义变量记录输入信息
    v1 = tk.StringVar()
    # 生成输入框
    entry1 = tk.Entry(window_function, show=None, textvariable=v1).grid(row=1, column=1, pady=40)
    # 生成按钮
    button = tk.Button(window_function, text="删除", command=delete_yg, anchor='s').place(relx=0.2, rely=0.5)
    button2 = tk.Button(window_function, text="返回", command=to_yg_page).place(relx=0.4, rely=0.5)
    # 显示窗口
    window_function.mainloop()


# 更新商品信息界面
def update_sp_page():
    # window_choice.destroy()
    global window_function
    global v1,v2,v3,v4,v5,v6
    window_function = tk.Tk()
    window_function.title("超市管理系统")
    width = 400
    height = 500
    screenwidth = window_function.winfo_screenwidth()
    screenheight = window_function.winfo_screenheight()
    size_geo = '%dx%d+%d+%d' % (width, height, (screenwidth - width) / 2, (screenheight - height) / 2)
    window_function.geometry(size_geo)

    tk.Label(window_function, text="更新商品信息", font=("黑体", 20)).grid(row=0, column=1, pady=20)
    tk.Label(window_function, text="请输入商品编号：").grid(row=1, column=0, padx=20, pady=20)
    tk.Label(window_function, text="请输入商品名称：").grid(row=2, column=0, padx=20, pady=20)
    tk.Label(window_function, text="请输入商品单价：").grid(row=3, column=0, padx=20, pady=20)
    tk.Label(window_function, text="请输入供应商编号：").grid(row=4, column=0, padx=20, pady=20)
    tk.Label(window_function, text="请输入商品简介：").grid(row=5, column=0, padx=20, pady=20)
    tk.Label(window_function, text="请输入备注内容：").grid(row=6, column=0, padx=20, pady=20)
    # 定义变量记录输入信息
    v1 = tk.StringVar()
    v2 = tk.StringVar()
    v3 = tk.StringVar()
    v4 = tk.StringVar()
    v5 = tk.StringVar()
    v6 = tk.StringVar()
    entry1 = tk.Entry(window_function, show=None, textvariable=v1).grid(row=1, column=1)
    entry2 = tk.Entry(window_function, show=None, textvariable=v2).grid(row=2, column=1)
    entry3 = tk.Entry(window_function, show=None, textvariable=v3).grid(row=3, column=1)
    entry3 = tk.Entry(window_function, show=None, textvariable=v4).grid(row=4, column=1)
    entry3 = tk.Entry(window_function, show=None, textvariable=v5).grid(row=5, column=1)
    entry3 = tk.Entry(window_function, show=None, textvariable=v6).grid(row=6, column=1)
    button = tk.Button(window_function, text="更新", command=update_sp).place(relx=0.3, rely=0.9)
    button2 = tk.Button(window_function, text="返回", command=to_sp_page).place(relx=0.5, rely=0.9)
    window_function.mainloop()


# 条件查找商品界面
def select_sp_page():
    # window_choice.destroy()
    global window_function
    global v1
    window_function = tk.Tk()
    window_function.title("超市管理系统")
    width = 400
    height = 500
    screenwidth = window_function.winfo_screenwidth()
    screenheight = window_function.winfo_screenheight()
    size_geo = '%dx%d+%d+%d' % (width, height, (screenwidth - width) / 2, (screenheight - height) / 2)
    window_function.geometry(size_geo)

    tk.Label(window_function, text="查找商品信息", font=("黑体", 20)).grid(row=0, column=1, pady=20)
    tk.Label(window_function, text="请输入商品编号：").grid(row=1, column=0, padx=20)
    v1 = tk.StringVar()
    entry1 = tk.Entry(window_function, show=None, textvariable=v1).grid(row=1, column=1, pady=40)
    button = tk.Button(window_function, text="查找", command=select_sp).place(relx=0.3, rely=0.5)
    button2 = tk.Button(window_function, text="返回", command=to_sp_page).place(relx=0.5, rely=0.5)
    window_function.mainloop()


def addsp_addpage():
    window_function.destroy()
    add_sp_page()


def change1_add():
    window_function.destroy()
    add_sp()


def change1_delete():
    window_function.destroy()
    delete_sp()


def change1_update():
    window_function.destroy()
    update_sp()


def change1_select():
    window_function.destroy()
    select_sp()


def to_manager_page():
    window_function.destroy()
    manager_page()


def to_login_page():
    window.destroy()
    login_page()


def to_gys_page():
    window_function.destroy()
    gys_page()


def to_sp_page():
    window_function.destroy()
    gys_page()


def to_yg_page():
    window_function.destroy()
    yg_page()


'''
# 验证用户登录
def validate_login():
    # 连接数据库
    connect = pymysql.connect(host="localhost", user="root", password="hsb010811", database="618")
    # 创建光标
    cursor = connect.cursor()
    employee_id = employee_id_entry.get()
    password = password_entry.get()
    level = level_entry.get()
    sql = "select * from 员工表 where 员工编号 = %s and 员工密码 = %s and 员工级别 = %s" % (employee_id, password, level)
    result = cursor.fetchall()
    connect.close()
    return result   '''


# 登录
def submit():
    employee_id = employee_id_entry.get()
    password = password_entry.get()
    level = level_entry.get()
    if (employee_id == "yg1001" and password == "00006789" and level == '00') or (employee_id == "yg1002" and password == "00006790" and level == '10') or (
            employee_id == "yg0108" and password == "00123742" and level == '00') or (
            employee_id == "yg0602" and password == "01080602" and level == '20') or (
            employee_id == "yg1080" and password == "10181234" and level == '10') or (employee_id == "yg4024" and password == "02403218" and level == '20'):
        messagebox.showinfo("登录成功", "欢迎进入超市管理系统！")
        if level == '00':  # 管理员
            root.destroy()
            manager_page()
        else:
            root.destroy()
            ordinary_page()
    else:
        messagebox.showerror("登录失败", "员工号、密码或级别错误，请重试。")


# 登录界面
def login_page():
    global root
    root = tk.Tk()
    root.title("登录")
    root.geometry("400x500")
    root.resizable(False, False)

    # 设置窗口在屏幕中间弹出
    root.withdraw()
    root.update_idletasks()
    x = (root.winfo_screenwidth() - root.winfo_reqwidth()) // 2
    y = (root.winfo_screenheight() - root.winfo_reqheight()) // 2
    root.geometry("+%d+%d" % (x, y))
    root.deiconify()

    # 创建标签和输入框
    label = tk.Label(root, text="超市管理系统", font=("黑体", 16))
    label.grid(row=0, column=0, columnspan=2, pady=10)

    employee_id_label = tk.Label(root, text="员工编号:")
    employee_id_label.grid(row=1, column=0, padx=10, pady=5)
    global employee_id_entry
    employee_id_entry = tk.Entry(root)
    employee_id_entry.grid(row=1, column=1, padx=10, pady=5)

    password_label = tk.Label(root, text="员工密码:")
    password_label.grid(row=2, column=0, padx=10, pady=5)
    global password_entry
    password_entry = tk.Entry(root, show="*")
    password_entry.grid(row=2, column=1, padx=10, pady=5)

    level_label = tk.Label(root, text="员工级别:")
    level_label.grid(row=3, column=0, padx=10, pady=5)
    global level_entry
    level_entry = tk.Entry(root)
    level_entry.grid(row=3, column=1, padx=10, pady=5)

    # 创建提交按钮
    submit_button = tk.Button(root, text="登录", command=submit)
    submit_button.grid(row=4, column=0, columnspan=2, pady=10)

    root.mainloop()


# 管理员界面
def manager_page():
    global root_manager
    root_manager = tk.Tk()
    root_manager.title("管理员")
    root_manager.geometry("500x500")
    root_manager.resizable(False, False)

    # 设置窗口在屏幕中间弹出
    root_manager.withdraw()
    root_manager.update_idletasks()
    x = (root_manager.winfo_screenwidth() - root_manager.winfo_reqwidth()) // 2
    y = (root_manager.winfo_screenheight() - root_manager.winfo_reqheight()) // 2
    root_manager.geometry("+%d+%d" % (x, y))
    root_manager.deiconify()

    tk.Label(root_manager, text="欢迎进入管理员界面", font=("黑体", 20)).pack(pady=10)
    button1 = tk.Button(root_manager, text="供应商管理", command=gys_page).pack(pady=10)
    button2 = tk.Button(root_manager, text="商品管理", command=gys_page).pack(pady=10)
    button3 = tk.Button(root_manager, text="员工管理", command=gys_page).pack(pady=10)
    button4 = tk.Button(root_manager, text="采购管理", command=gys_page).pack(pady=10)
    button5 = tk.Button(root_manager, text="退出", command=login_page).pack(pady=10)


# 普通员工界面
def ordinary_page():
    global root_ordinary
    root_ordinary = tk.Tk()
    root_ordinary.title("普通员工")
    root_ordinary.geometry("500x500")
    root_ordinary.resizable(False, False)

    # 设置窗口在屏幕中间弹出
    root_ordinary.withdraw()
    root_ordinary.update_idletasks()
    x = (root_ordinary.winfo_screenwidth() - root_ordinary.winfo_reqwidth()) // 2
    y = (root_ordinary.winfo_screenheight() - root_ordinary.winfo_reqheight()) // 2
    root_ordinary.geometry("+%d+%d" % (x, y))
    root_ordinary.deiconify()

    tk.Label(root_ordinary, text="欢迎进入查询界面", font=("黑体", 20)).pack(pady=10)
    button1 = tk.Button(root_ordinary, text="查询员工信息", command=select_sp_page).pack(pady=10)
    button2 = tk.Button(root_ordinary, text="查询商品信息", command=select_sp_page).pack(pady=10)
    button3 = tk.Button(root_ordinary, text="查询采购信息", command=select_sp_page).pack(pady=10)
    button4 = tk.Button(root_ordinary, text="退出", command=login_page).pack(pady=10)


# 供应商管理界面
def gys_page():
    root_manager.destroy()
    global window
    window = tk.Tk()
    window.title("超市管理系统")
    # 设置窗口在屏幕中间弹出
    window.withdraw()
    window.update_idletasks()  # 必须先更新窗口信息
    x = (window.winfo_screenwidth() - window.winfo_reqwidth()) / 2
    y = (window.winfo_screenheight() - window.winfo_reqheight()) / 2
    window.geometry("+%d+%d" % (x, y))
    window.deiconify()

    tk.Label(window, text="欢迎进入供应商管理界面", font=("黑体", 20)).pack(pady=10)
    button1 = tk.Button(window, text="添加信息", command=add_gys_page).pack(pady=10)
    button2 = tk.Button(window, text="删除信息", command=delete_gys_page).pack(pady=10)
    button3 = tk.Button(window, text="修改信息", command=delete_gys_page).pack(pady=10)
    button4 = tk.Button(window, text="信息查询", command=delete_gys_page).pack(pady=10)
    button5 = tk.Button(root_manager, text="返回", command=manager_page).pack(pady=10)

    window.mainloop()


# 商品管理界面
def sp_page():
    # root_manager.destroy()
    global window
    window = tk.Tk()
    window.title("超市管理系统")
    # 设置窗口在屏幕中间弹出
    window.withdraw()
    window.update_idletasks()  # 必须先更新窗口信息
    x = (window.winfo_screenwidth() - window.winfo_reqwidth()) / 2
    y = (window.winfo_screenheight() - window.winfo_reqheight()) / 2
    window.geometry("+%d+%d" % (x, y))
    window.deiconify()

    tk.Label(window, text="欢迎进入商品管理界面", font=("黑体", 20)).pack(pady=10)
    button1 = tk.Button(window, text="添加信息", command=add_sp_page).pack(pady=10)
    button2 = tk.Button(window, text="删除信息", command=delete_sp_page).pack(pady=10)
    button3 = tk.Button(window, text="修改信息", command=delete_sp_page).pack(pady=10)
    button4 = tk.Button(window, text="信息查询", command=delete_sp_page).pack(pady=10)
    button5 = tk.Button(root_manager, text="返回", command=manager_page).pack(pady=10)

    window.mainloop()


# 员工管理界面
def yg_page():
    # root_manager.destroy()
    global window
    window = tk.Tk()
    window.title("超市管理系统")
    # 设置窗口在屏幕中间弹出
    window.withdraw()
    window.update_idletasks()  # 必须先更新窗口信息
    x = (window.winfo_screenwidth() - window.winfo_reqwidth()) / 2
    y = (window.winfo_screenheight() - window.winfo_reqheight()) / 2
    window.geometry("+%d+%d" % (x, y))
    window.deiconify()

    tk.Label(window, text="欢迎进入员工管理界面", font=("黑体", 20)).pack(pady=10)
    button1 = tk.Button(window, text="添加信息", command=add_yg_page).pack(pady=10)
    button2 = tk.Button(window, text="删除信息", command=delete_yg_page).pack(pady=10)
    button3 = tk.Button(window, text="修改信息", command=delete_yg_page).pack(pady=10)
    button4 = tk.Button(window, text="信息查询", command=delete_yg_page).pack(pady=10)
    button5 = tk.Button(root_manager, text="返回", command=manager_page).pack(pady=10)

    window.mainloop()


if __name__ == '__main__':
    login_page()
